package com.itheima.day05;

/*
案例4: 利用方法数组遍历
        //打印格式[12,14,23,15,16]
 */

public class TestClassCase04 {

    public static void main(String[] args) {

        int[] num={12,14,23,15,16};
       // int[] num=null;
        forPrint(num);
        System.out.println("不会打架啊");
    }


    public static void forPrint(int[] arr){

        if(arr==null){          //在定义方法时,应该确保方法的健壮性
            System.out.println("请正确输入数组!");
            return;
        }

        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {

           if (i==arr.length-1) {
               System.out.println(arr[i] + "]");
           }else{
               System.out.print(arr[i]+",");
           }
        }
    }
}
